#!/usr/bin/perl -w
#
# show  engines for ECM mysql_ecm_storage_engines
# @param $1 install home
# @param $2 pattern
# @param $3 delimiter
# @param $4 host
# @param $5 port
# @param $6 username
# @param $7 password
# -- Modify  2009.06.15 by DavidLi -if mysql version  <= 5.0 , program will report warning
# -- Created 2009.06.03 by DavidLi -initial

use strict;
my $SQL="show engines";
my ($MYSQL_HOME,$RE,$DELIM,$HOST,$PORT,$USER,$PASS) = @ARGV;

my $PARAM="";
$PARAM="$PARAM -h\"$HOST\"" if (defined($HOST) && $HOST ne "");
$PARAM="$PARAM -P\"$PORT\"" if (defined($PORT) && $PORT ne "");
$PARAM="$PARAM -u\"$USER\"" if (defined($USER) && $USER ne "");
$PARAM="$PARAM -p\"$PASS\"" if (defined($PASS) && $PASS ne "");
my $MYSQL= defined ($MYSQL_HOME) ? "$MYSQL_HOME/bin/mysql" : "mysql";
#my $MYSQL="$MYSQL_HOME/bin/mysql";
my $MYSQLADMIN= defined $MYSQL_HOME ? "$MYSQL_HOME/bin/mysqladmin" : "mysqladmin";
#my $MYSQLADMIN="$MYSQL_HOME/bin/mysqladmin"; 
if ($^O =~ m/MSWin32/) {
  $MYSQL =~ s/\//\\/g;
  $MYSQLADMIN =~ s/\//\\/g;
}
# Check if mysqld is alive
#my $retmsg=`$MYSQLADMIN $PARAM ping 2>&1`;
#chomp($retmsg);
#if ( "$retmsg" ne "mysqld is alive" ) {
#    print "em_error=Status${DELIM}Down\n";
#    exit 1;
#}

my @lines=`$MYSQL -N -s $PARAM --batch  -e"$SQL"`;
#print "@lines";


foreach my $line (@lines) {
  my $str="";
  chomp $line;
  my @row = split(/\t/,$line);
  #if mysql version <= 5.0, trx,xa,savepoint return "NULL"
  my $row2 =defined $row[2] ? "$row[2]" : "NULL";
  my $row3 =defined $row[3] ? "$row[3]" : "NULL";
  my $row4 =defined $row[4] ? "$row[4]" : "NULL";
  my $row5 =defined $row[5] ? "$row[5]" : "NULL";
  # engine|support|comment|trx|xa|savepoint
  print "em_result=$row[0]|$row[1]|$row2|$row3|$row4|$row5\n"
}



